package com.sdgakj.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * 响应返回JSON 数据
 * Created by Administrator on 2016/4/11.
 */
public class RequestUtils {

    public static final Integer SUCCESS = 1;
    public static final Integer FAILURE = 0;

    public static final String SUCCESS_REQUEST = "操作成功";
    public static final String FAILURE_REQUEST = "操作失败";

    public static final String ERROR_ARGS = "参数错误";
    public static final String REQUEST_FAILURE = "请求失败";

    public static JSONObject success(int success, Object object, String resMsg) {
        JSONObject result = new JSONObject();

        result.put("resCode", success);
        result.put("data", object);
        result.put("resMsg", resMsg);

        return result;
    }

    public static JSONObject success(Object object, String resMsg) {
        return success(SUCCESS, object, resMsg);
    }

    public static JSONObject success(Object object) {
        return success(SUCCESS, object, SUCCESS_REQUEST);
    }


    public static JSONObject failure(int success, Object object, String resMsg) {
        JSONObject result = new JSONObject();

        result.put("resCode", success);
        result.put("data", object);
        result.put("resMsg", resMsg);

        return result;
    }

    public static JSONObject failure(Object object, String resMsg) {
        return failure(FAILURE, object, resMsg);
    }

    public static JSONObject failure(String resMsg) {
        return failure(FAILURE, "", resMsg);
    }

    public static JSONObject failure() {
        return failure(FAILURE_REQUEST);
    }
}
